//
//  EditInformationViewController.m
//  OfferJob
//
//  Created by 河南动力无限科技有限公司 on 17/7/12.
//  Copyright © 2017年 郑州动力无限科技. All rights reserved.
//

#import "EditInformationViewController.h"
#import "CellView.h"


@interface EditInformationViewController ()<UITextFieldDelegate>
{
    UITextView* _textView;
    
    UITextView* _textVie;
}
@property (nonatomic,strong)UIScrollView* scrollView;
@property(nonatomic,assign)NSInteger currBtnTag;
@property(nonatomic,strong)NSString* infoID;
@property(nonatomic,strong)NSMutableDictionary* dic;

@end

@implementation EditInformationViewController

- (void)viewDidLoad {
       self.title = @"编辑资料";
    [super viewDidLoad];
  
    _dic=[[NSMutableDictionary alloc]init];
    _scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
    _scrollView.backgroundColor=backgroundcolor;
    //    [_scrollView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view addSubview:_scrollView];
     _currBtnTag=1;
    
  
    
    [self getINfo];
    
}

- (void)getINfo{

    
    FXTHttpRequestModel * requestModel = [[FXTHttpRequestModel alloc] init];
    requestModel.type = FXTHttpType_GET;
    requestModel.appendUrl = @"/User/user_info";
    NSMutableDictionary * paramDic = [NSMutableDictionary dictionary];
    [paramDic setValue:tokenn forKey:@"token"];
    requestModel.paramDic = paramDic;
    requestModel.callback = ^(FXTHttpResponseModel * result, NSError *error){
        if (result.state ==FXTReponseCodeState_Success) {
            NSLog(@"请求的结果是%@",result.data);
            _dic=result.data;
            _infoID=[result.data  objectForKey:@"info_id"];
      [self setUI];
            [_scrollView refreshControl];
        }else {
            [DisplayHelper displayWarningAlert:result.alertMsg];
        }
    };
    [[FXTHttpSessionManager sharedHttpSessionManager] sendHttpRequestParam:requestModel];



}
- (void)setUI{
    
    UILabel*_titleLB=[[UILabel alloc]initWithFrame:CGRectMake(10*kAppScale, 0*kAppScale,SCREEN_WIDTH-20*kAppScale,35*kAppScale)];
    _titleLB.textColor=[UIColor redColor];
    _titleLB.textAlignment=NSTextAlignmentLeft;
    _titleLB.text=@"* 为必填项 完善自己的简历";
    _titleLB.font=[UIFont systemFontOfSize:13*kAppScale];
    [_scrollView addSubview:_titleLB];
    
////    WithFrame:CGRectMake(10*kAppScale,_titleLB.bottom, SCREEN_WIDTH-20*kAppScale, 220*kAppScale)
//    UIView* firstV=[[UIView alloc]init];
//    firstV.backgroundColor=[UIColor whiteColor];
//    [_scrollView  addSubview:firstV];
    NSString* ww;
    NSString *xueStr = [NSString stringWithFormat:@"%@",[_dic  objectForKey:@"degrees"]] ;
    if ([xueStr isEqualToString:@"1"]) {
        ww=@"专科";
    }else if ([xueStr isEqualToString:@"2"]) {
        ww=@"本科";
    }else if ([xueStr isEqualToString:@"3"]){
        ww=@"研究生";
    }
    
//    if (_currBtnTag== [_dic  objectForKey:@"sex"]) {
//        return;
//    }
//    UIButton *jiuBtn=(UIButton *)[self.view viewWithTag:_currBtnTag];
//    jiuBtn.selected=NO;
//    
//    jiuBtn.selected=YES;
//    _currBtnTag=[_dic  objectForKey:@"sex"];
//    
//    
//    NSString* sex;
    NSString *sexStr = [NSString stringWithFormat:@"%@",[_dic  objectForKey:@"sex"]] ;
    if ([sexStr isEqualToString:@"1"]) {
      UIButton *jiuBtn=(UIButton *)[self.view viewWithTag:1];
        jiuBtn.selected=YES;
    }else if ([xueStr isEqualToString:@"2"]) {
        UIButton *jiuBtn=(UIButton *)[self.view viewWithTag:2];
        jiuBtn.selected=YES;
    }
    
    float setY=_titleLB.bottom;
    setY+=10;
    
    NSArray *textArr=@[[_dic objectForKey:@"name"] ,@"",ww,[_dic objectForKey:@"major"],[_dic objectForKey:@"specialty"]];
    NSArray *MArr=@[@"姓名:",@"性别:",@"学历:",@"专业:",@"特长:"];
    NSArray *VArr=@[@"请输入姓名",@" ",@"请选择学历",@"请输入专业",@"请输入特长"];
    for (int i=0; i<[MArr count]; i++) {
        CellView *cell=[[CellView alloc]initWithFrame:CGRectMake(10*kAppScale, setY, self.view.width-20*kAppScale, 44*kAppScale)];
        cell.titleLabel.textColor=blackTextColor;
        cell.titleLabel.text=MArr[i];
        cell.titleLabel.textAlignment=NSTextAlignmentLeft;
        
        if (i==0||i==1||i==2||i==3) {
            cell.titleLabel.attributedText = [[NSString stringWithFormat:@"<red11>%@</red11><heise14>%@</heise14>",@"*",MArr[i]] attributedStringWithStyleBook:[self Style]];
        }

        UITextField *textF=[[UITextField alloc]initWithFrame:CGRectMake(60*kAppScale, 7*kAppScale, 280*kAppScale, cell.height-10*kAppScale)];
        textF.font=[UIFont systemFontOfSize:13*kAppScale];
        textF.placeholder=VArr[i];
        textF.text=textArr[i];
        textF.delegate=self;
        textF.tag=10+i;
        [cell addSubview:textF];
        
        if (i==1) {
            for (int i=0; i<2; i++) {
                UIButton *btn=[UIButton buttonWithType:0];
                btn.frame=CGRectMake(170/2.25*kAppScale*i+70*kAppScale,7*kAppScale, 150/2.25*kAppScale, 80/2.25*kAppScale);
                [btn setImage:[UIImage imageNamed:@"icon_qqqq"] forState:0];
                [btn setImage:[UIImage imageNamed:@"icon_quanquan"] forState:UIControlStateSelected];
                btn.tag=i+1;
                [btn addTarget:self action:@selector(seleDianTi:) forControlEvents:1<<6];
                [btn setTitleColor:grayTextColor forState:0];
                [btn setTitle:i==0?@"男":@"女" forState:0];
                btn.titleLabel.font=[UIFont systemFontOfSize:13*kAppScale];
                [cell addSubview:btn];
                [btn TiaoZhengButtonWithOffsit:10 TextImageSite:UIButtonTextRight];
                
                if (btn.tag==_currBtnTag) {
                    btn.selected=YES;
                }
            }
        }
        
        
        [_scrollView addSubview:cell];
        setY=cell.bottom;
    }
     setY=10*kAppScale+setY;
    
    
    
    NSArray *MArrt=@[@"电话:",@"意向:"];
    NSArray *vArrt=@[@"请输入电话",@"请输入意向"];
     NSArray *texArr=@[[NSString stringWithFormat:@"%@",[_dic objectForKey:@"user_phone"]] ,[_dic objectForKey:@"intent"]];
    for (int i=0; i<[MArrt count]; i++) {
        CellView *cell=[[CellView alloc]initWithFrame:CGRectMake(10*kAppScale, setY, self.view.width-20*kAppScale, 44*kAppScale)];
        cell.titleLabel.textColor=blackTextColor;
        cell.titleLabel.font=[UIFont  systemFontOfSize:13*kAppScale];
        cell.titleLabel.textAlignment=NSTextAlignmentLeft;
           cell.titleLabel.attributedText = [[NSString stringWithFormat:@"<red11>%@</red11><heise14>%@</heise14>",@"*",MArrt[i]] attributedStringWithStyleBook:[self Style]];
        
   
        UITextField *textF=[[UITextField alloc]initWithFrame:CGRectMake(60*kAppScale, 7*kAppScale, 290*kAppScale, cell.height-10*kAppScale)];
        textF.font=[UIFont systemFontOfSize:13*kAppScale];
        textF.placeholder=vArrt[i];
        textF.text=texArr[i];
       textF.delegate=self;
        textF.tag=100+i;
        [cell addSubview:textF];
        
        //        cell.contentLabel.frame=CGRectMake(cell.titleLabel.right+80*self.scale, 0, 80*self.scale, 44*self.scale);
        [_scrollView addSubview:cell];
        setY=cell.bottom;
    }
    setY=10*kAppScale+setY;
    
    
        UIView* firstV=[[UIView alloc]initWithFrame:CGRectMake(10*kAppScale, setY, SCREEN_WIDTH-20*kAppScale, 300*kAppScale)];
        firstV.backgroundColor=[UIColor whiteColor];
        [_scrollView  addSubview:firstV];
   UILabel*titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(10*kAppScale, 10*kAppScale,100*kAppScale, 35*kAppScale)];
    titleLabel.font=[UIFont systemFontOfSize:13*kAppScale];
    titleLabel.textColor = blackTextColor;
       titleLabel.attributedText = [[NSString stringWithFormat:@"<red11>%@</red11><heise14>%@</heise14>",@"*",@"自我介绍"] attributedStringWithStyleBook:[self Style]];
    titleLabel.textAlignment=NSTextAlignmentLeft;
    [firstV  addSubview:titleLabel];
    
    UIView* lineV=[[UIView alloc]initWithFrame:CGRectMake(10*kAppScale,titleLabel.bottom, SCREEN_WIDTH-20*kAppScale, 0.5)];
    lineV.backgroundColor=blackLineColore;
    [firstV addSubview:lineV];
    
    
    
   _textView=[[UITextView alloc]initWithFrame:CGRectMake(0, lineV.bottom+5*kAppScale, SCREEN_WIDTH-20*kAppScale, 60*kAppScale)];
    _textView.placeholder=@"请填写自己的基本信息简介";
    _textView.text=[NSString stringWithFormat:@"%@",[_dic objectForKey:@"introduce"]];
    [firstV addSubview:_textView];
    
    
    UILabel*titleLab=[[UILabel alloc]initWithFrame:CGRectMake(10*kAppScale,_textView.bottom+5*kAppScale,100*kAppScale, 35*kAppScale)];
    titleLab.font=[UIFont systemFontOfSize:13*kAppScale];
    titleLab.textColor = blackTextColor;
     titleLab.attributedText = [[NSString stringWithFormat:@"<red11>%@</red11><heise14>%@</heise14>",@"*",@"工作经验"] attributedStringWithStyleBook:[self Style]];
    titleLab.textAlignment=NSTextAlignmentLeft;
    [firstV  addSubview:titleLab];
    
    UIView* line=[[UIView alloc]initWithFrame:CGRectMake(10*kAppScale,titleLab.bottom, SCREEN_WIDTH-20*kAppScale, 0.5)];
    line.backgroundColor=blackLineColore;
    [firstV addSubview:line];
    
 
    
    _textVie=[[UITextView alloc]initWithFrame:CGRectMake(0, line.bottom+5*kAppScale, SCREEN_WIDTH-20*kAppScale, 60*kAppScale)];
    _textVie.placeholder=@"请填写自己近一年的工作经历";
      _textView.text=[NSString stringWithFormat:@"%@",[_dic objectForKey:@"experience"]];
    [firstV addSubview:_textVie];
    
    
   
    UIButton *nextBtn=[[UIButton alloc]initWithFrame:CGRectMake(10*kAppScale,firstV.bottom+10*kAppScale,SCREEN_WIDTH-20*kAppScale,44*kAppScale)];
    nextBtn.backgroundColor=NavCOLOR;
    [nextBtn setTitle:@"保存" forState:UIControlStateNormal];
    [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    nextBtn.titleLabel.font=[UIFont systemFontOfSize:12*kAppScale];
    [nextBtn addTarget:self action:@selector(nextBtnEvent) forControlEvents:UIControlEventTouchUpInside];
    [_scrollView addSubview:nextBtn];
    _scrollView.contentSize=CGSizeMake(SCREEN_WIDTH, nextBtn.bottom+10*kAppScale);
    
    
    
    
    
    
}
- (void)seleDianTi:(UIButton*)btn{


    if (_currBtnTag==btn.tag) {
        return;
    }
    UIButton *jiuBtn=(UIButton *)[self.view viewWithTag:_currBtnTag];
    jiuBtn.selected=NO;
    
    btn.selected=YES;
    _currBtnTag=btn.tag;

}


- (void)nextBtnEvent{
    UITextField *nameField = (UITextField *)[self.view viewWithTag:10];
    NSString *nameStr = nameField.text ;

    int ww;
    UITextField *xueField = (UITextField *)[self.view viewWithTag:12];
    NSString *xueStr = xueField.text ;
    if ([xueStr isEqualToString:@"专科"]) {
        ww=1;
    }else if ([xueStr isEqualToString:@"本科"]) {
        ww=2;
    }else if ([xueStr isEqualToString:@"研究生"]){
        ww=3;
    }
    
    
    
    UITextField *zhuanyeField = (UITextField *)[self.view viewWithTag:13];
    NSString *zhuanStr = zhuanyeField.text ;
    
    UITextField *teField = (UITextField *)[self.view viewWithTag:14];
    NSString *rechangStr = teField.text ;
    
    UITextField *telField = (UITextField *)[self.view viewWithTag:100];
    NSString *telStr = telField.text ;
    
    UITextField *yixangField = (UITextField *)[self.view viewWithTag:101];
    NSString *yixiangStr = yixangField.text ;
    
    
    
    FXTHttpRequestModel * requestModel = [[FXTHttpRequestModel alloc] init];
    requestModel.type = FXTHttpType_POST;
    requestModel.appendUrl = @"/User/user_info";
    NSMutableDictionary * paramDic = [NSMutableDictionary dictionary];
    [paramDic setValue:tokenn forKey:@"token"];
        [paramDic setValue:nameStr forKey:@"name"];
        [paramDic setValue:[NSString stringWithFormat:@"%ld",(long)_currBtnTag]  forKey:@"sex"];
        [paramDic setValue:[NSString stringWithFormat:@"%d",ww] forKey:@"degrees"];
        [paramDic setValue:zhuanStr forKey:@"major"];
        [paramDic setValue:yixiangStr forKey:@"intent"];
        [paramDic setValue:rechangStr forKey:@"specialty"];
        [paramDic setValue:_textView.text forKey:@"introduce"];
     [paramDic setValue:telStr forKey:@"user_phone"];
         [paramDic setValue:_textVie.text forKey:@"experience"];
             [paramDic setValue:_infoID forKey:@"info_id"];
       requestModel.paramDic = paramDic;
    requestModel.callback = ^(FXTHttpResponseModel * result, NSError *error){
        if (result.state ==FXTReponseCodeState_Success) {
            NSLog(@"请求的结果是%@",result.data);
                     [DisplayHelper displayWarningAlert:result.alertMsg];

            
        }else {
            [DisplayHelper displayWarningAlert:result.alertMsg];
        }
    };
    [[FXTHttpSessionManager sharedHttpSessionManager] sendHttpRequestParam:requestModel];
    

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
